home *** CD-ROM | disk | FTP | other *** search
/ Visual Basic Source Code / Visual Basic Source Code.iso / vbsource / jpi / graphics.bas < prev    next >
Encoding:
BASIC Source File  |  1998-01-29  |  45.7 KB  |  1,267 lines

  1. Attribute VB_Name = "GraphicsEngine"
  2. Declare Function SetWindowPos Lib "user32" (ByVal hwnd As Long, ByVal hWndInsertAfter As Long, ByVal X As Long, ByVal Y As Long, ByVal cx As Long, ByVal cy As Long, ByVal wFlags As Long) As Long
  3. Global ResolutionX As Integer
  4. Global ResolutionY As Integer
  5. Global ResolutionMidX As Integer
  6. Global ResolutionMidY As Integer
  7. Global ColorDepth As Integer
  8.  
  9. ' Transparent Blit
  10. Option Compare Text
  11.  
  12. Global WindowRect As RECT
  13. ' Win32
  14. Const IMAGE_BITMAP = 0
  15. Const LR_LOADFROMFILE = &H10
  16. Const LR_CREATEDIBSECTION = &H2000
  17. Const SRCCOPY = &HCC0020
  18.  
  19. Global BattleSurfaceRect As RECT
  20.  
  21. Global Const FONT_SPACINGX = 8
  22. Global Const FONT_SPACINGY = 12
  23. Global Const FONT_SIZE = 12
  24. Global FONT_LastCharacter As Integer
  25. Global FONT_LastLine As Integer
  26. Private FxClear As DDBLTFX
  27. Private Type GfxEng
  28.   TotalRefresh As Boolean
  29.   DeviceOpen As Boolean
  30.   TerrainRefreshSize As Integer
  31. End Type
  32. Public GraphicsEngineData As GfxEng
  33. Private Type BITMAP
  34.   bmType  As Long
  35.   bmWidth  As Long
  36.   bmHeight  As Long
  37.   bmWidthBytes  As Long
  38.   bmPlanes  As Integer
  39.   bmBitsPixel  As Integer
  40.   bmBits  As Long
  41. End Type
  42. ' GDI32
  43.  
  44. Private Declare Function CreateCompatibleDC Lib "gdi32" (ByVal hdc As Long) As Long
  45. Private Declare Function DeleteDC Lib "gdi32" (ByVal hdc As Long) As Long
  46. Private Declare Function DeleteObject Lib "gdi32" (ByVal hObject As Long) As Long
  47. Private Declare Function GetObject Lib "gdi32" Alias "GetObjectA" (ByVal hObject As Long, ByVal nCount As Long, lpObject As Any) As Long
  48. Private Declare Function SelectObject Lib "gdi32" (ByVal hdc As Long, ByVal hObject As Long) As Long
  49. ' USER32
  50. Private Declare Function GetDC Lib "user32" (ByVal hwnd As Long) As Long
  51. Private Declare Function LoadImage Lib "user32" Alias "LoadImageA" (ByVal hInst As Long, ByVal lpsz As String, ByVal un1 As Long, ByVal n1 As Long, ByVal n2 As Long, ByVal un2 As Long) As Long
  52. Private Declare Function StretchBlt Lib "gdi32" (ByVal hdc As Long, ByVal X As Long, ByVal Y As Long, ByVal nWidth As Long, ByVal nHeight As Long, ByVal hSrcDC As Long, ByVal xSrc As Long, ByVal ySrc As Long, ByVal nSrcWidth As Long, ByVal nSrcHeight As Long, ByVal dwRop As Long) As Long
  53. Private Declare Function SetPixelV Lib "gdi32" (ByVal hdc As Long, ByVal X As Long, ByVal Y As Long, ByVal crColor As Long) As Long
  54. Private Declare Function ShowCursor Lib "user32" (ByVal bShow As Long) As Long
  55. '&HCC0020 is the dwRop (raster operation) thingy for using stretchblt to copy a pic
  56. Dim dd As DirectDraw2
  57. 'Terrain
  58. Private TerrainSurface As DirectDrawSurface3
  59. 'Battleview
  60. Private BattleSurface As DirectDrawSurface3
  61. 'Control panel
  62. Private ControlPanelSurface As DirectDrawSurface3
  63.  
  64. Private ddsdFront As DDSURFACEDESC      ' Front surface description
  65. Private ddsFront As DirectDrawSurface3  ' Front buffer
  66. Private ddsBack As DirectDrawSurface3
  67. Private fx As DDBLTFX
  68.  
  69. Private ddCaps As DDSCAPS               ' Capabilities for search
  70. Private lhdc As Long                    ' hDC for back buffer
  71. Private PFormat1 As DDPIXELFORMAT
  72. Global Const LINEMODE_NORMAL = 1
  73. Global Const LINEMODE_SHADE = 2
  74. Global Const BltType_Mask = 1
  75. Global Const BltType_Fast = 2
  76. Global GraphicSurfaces(100) As DirectDrawSurface3
  77. Sub prepSrcColorKey(srf As DirectDrawSurface3)
  78. Dim aColorkey As DDCOLORKEY
  79. aColorkey.dwColorSpaceHighValue = 0
  80. aColorkey.dwColorSpaceLowValue = 0
  81. srf.SetColorKey DDCKEY_SRCBLT, aColorkey
  82. End Sub
  83. Public Sub SplashGraphic(PicIndex)
  84. Dim SrcBox As RECT
  85. SrcBox.Left = Pics(PicIndex).SourceRect.Left
  86. SrcBox.Top = Pics(PicIndex).SourceRect.Top
  87. SrcBox.bottom = Pics(PicIndex).Height + Pics(PicIndex).SourceRect.Top
  88. SrcBox.Right = Pics(PicIndex).Width + Pics(PicIndex).SourceRect.Left
  89. ddsBack.BltFast ResolutionMidX - Pics(PicIndex).HalfWidth, ResolutionMidY - Pics(PicIndex).HalfHeight, GraphicSurfaces(Pics(PicIndex).GraphicsLib), SrcBox, 0
  90.  
  91. End Sub
  92. Public Sub RefreshRender()
  93. TerrainSurface.Restore
  94. Call ControlPanelSurface.Restore
  95. Call RedrawControlPanel
  96. Call RenderTerrain
  97. End Sub
  98. Public Sub GethDC()
  99. ddsBack.GetDC lhdc
  100. End Sub
  101. Public Sub ReleasehDC()
  102. ddsBack.ReleaseDC lhdc
  103.  
  104. End Sub
  105. Public Sub DrawCursor()
  106. 'Cursor
  107. 'Call GraphicsEngine.PutGraphicOntoBackBuffer(Mouse.Position.X, Mouse.Position.Y, GameInterface.Mouse.CursorPic, BltType_Mask)
  108. End Sub
  109. Public Sub PutGraphicOntoBackBuffer(X, Y, PicIndex, BltType)
  110. Dim DestBox As RECT, SrcBox As RECT
  111. DestBox.Top = Y - Pics(PicIndex).HalfHeight
  112. DestBox.Left = X - Pics(PicIndex).HalfWidth
  113. DestBox.bottom = Y + Pics(PicIndex).HalfHeight
  114. DestBox.Right = X + Pics(PicIndex).HalfWidth
  115. SrcBox.Top = Pics(PicIndex).SourceRect.Top
  116. SrcBox.Left = Pics(PicIndex).SourceRect.Left
  117. SrcBox.bottom = Pics(PicIndex).SourceRect.Top + Pics(PicIndex).Height
  118. SrcBox.Right = Pics(PicIndex).SourceRect.Left + Pics(PicIndex).Width
  119. If DestBox.bottom > 0 Then
  120.   If DestBox.Top < ResolutionY Then
  121.     If DestBox.Right > 0 Then
  122.       If DestBox.Left < ResolutionX Then
  123.         If DestBox.Top < 0 Then
  124.           SrcBox.Top = SrcBox.Top - DestBox.Top
  125.           DestBox.Top = 0
  126.         End If
  127.         If DestBox.bottom > ResolutionY Then
  128.           SrcBox.bottom = SrcBox.bottom - (DestBox.bottom - ResolutionY)
  129.           DestBox.bottom = ResolutionY
  130.         End If
  131.         If DestBox.Left < 0 Then
  132.           SrcBox.Left = SrcBox.Left - DestBox.Left
  133.           DestBox.Left = 0
  134.         End If
  135.         If DestBox.Right > ResolutionX Then
  136.           SrcBox.Right = SrcBox.Right - (DestBox.Right - ResolutionX)
  137.           DestBox.Right = ResolutionX
  138.         End If
  139.         ' Set the transparent color
  140.         GraphicSurfaces(Pics(PicIndex).GraphicsLib).Restore
  141.         ' Blit the image to the back buffer
  142.         Select Case BltType
  143.         Case BltType_Mask
  144.           ddsBack.BltFast DestBox.Left, DestBox.Top, GraphicSurfaces(Pics(PicIndex).GraphicsLib), SrcBox, DDBLTFAST_WAIT Or DDBLTFAST_SRCCOLORKEY
  145.         Case BltType_Fast
  146.           ddsBack.BltFast DestBox.Left, DestBox.Top, GraphicSurfaces(Pics(PicIndex).GraphicsLib), SrcBox, 0
  147.         End Select
  148.       End If
  149.     End If
  150.   End If
  151. End If
  152.  
  153. End Sub
  154. Public Sub SwapScreen()
  155. ddsFront.Flip Nothing, 0
  156. End Sub
  157. Public Sub PutGraphicOntoTerrain(X, Y, PicIndex, Direction, BltType As Integer)
  158. Dim DestBox As RECT, SrcBox As RECT
  159. With Pics(PicIndex)
  160.     DestBox.Top = Y - .HalfHeight
  161.     DestBox.Left = X - .HalfWidth
  162.     DestBox.bottom = Y + .HalfHeight
  163.     DestBox.Right = X + .HalfWidth
  164.     SrcBox.Top = .SourceRect.Top
  165.     SrcBox.Left = .SourceRect.Left + (.Width * Direction)
  166.     SrcBox.bottom = .SourceRect.Top + .Height
  167.     SrcBox.Right = .SourceRect.Left + .Width + (.Width * Direction)
  168.     If DestBox.bottom > 0 Then
  169.       If DestBox.Top < BattleViewPort.Height Then
  170.         If DestBox.Right > 0 Then
  171.           If DestBox.Left < BattleViewPort.Width Then
  172.             If DestBox.Top < 0 Then
  173.               SrcBox.Top = SrcBox.Top - DestBox.Top
  174.               DestBox.Top = 0
  175.             End If
  176.             If DestBox.bottom > BattleViewPort.Height Then
  177.               SrcBox.bottom = SrcBox.bottom - (DestBox.bottom - BattleViewPort.Height)
  178.               DestBox.bottom = BattleViewPort.Height
  179.             End If
  180.             If DestBox.Left < 0 Then
  181.               SrcBox.Left = SrcBox.Left - DestBox.Left
  182.               DestBox.Left = 0
  183.             End If
  184.             If DestBox.Right > BattleViewPort.Width Then
  185.               SrcBox.Right = SrcBox.Right - (DestBox.Right - BattleViewPort.Width)
  186.               DestBox.Right = BattleViewPort.Width
  187.             End If
  188.             ' Set the transparent color
  189.             
  190.             
  191.             GraphicSurfaces(.GraphicsLib).Restore
  192.             ' Blit the image to the back buffer
  193.             Select Case BltType
  194.             Case BltType_Mask
  195.               TerrainSurface.BltFast DestBox.Left, DestBox.Top, GraphicSurfaces(.GraphicsLib), SrcBox, DDBLTFAST_WAIT Or DDBLTFAST_SRCCOLORKEY
  196.             Case BltType_Fast
  197.               TerrainSurface.BltFast DestBox.Left, DestBox.Top, GraphicSurfaces(.GraphicsLib), SrcBox, 0
  198.             End Select
  199.           End If
  200.         End If
  201.       End If
  202.     End If
  203. End With
  204. End Sub
  205. Public Sub PutGraphicOntoBattleView(X, Y, PicIndex, Direction, SpriteXOffset, SpriteYOffset)
  206. Dim DestBox As RECT, SrcBox As RECT
  207. On Error Resume Next
  208. With Pics(PicIndex)
  209.     DestBox.Top = Y - SpriteYOffset
  210.     DestBox.Left = X - SpriteXOffset
  211.     DestBox.bottom = (Y - SpriteYOffset) + .Height
  212.     DestBox.Right = (X - SpriteXOffset) + .Width
  213.     SrcBox.Top = .SourceRect.Top
  214.     SrcBox.Left = .SourceRect.Left + (.Width * Direction)
  215.     SrcBox.bottom = .SourceRect.Top + .Height
  216.     SrcBox.Right = .SourceRect.Left + (.Width * (Direction + 1))
  217. End With
  218. With DestBox
  219.   If .bottom > 0 Then
  220.     If .Top < BattleSurfaceRect.bottom Then
  221.       If .Right > 0 Then
  222.         If .Left < BattleSurfaceRect.Right Then
  223.           If .Top < 0 Then
  224.             SrcBox.Top = SrcBox.Top - .Top
  225.             .Top = 0
  226.           End If
  227.           If .bottom > BattleSurfaceRect.bottom Then
  228.             SrcBox.bottom = SrcBox.bottom - (.bottom - BattleSurfaceRect.bottom)
  229.           End If
  230.           If .Left < 0 Then
  231.             SrcBox.Left = SrcBox.Left - .Left
  232.             .Left = 0
  233.           End If
  234.           If .Right > BattleSurfaceRect.Right Then
  235.             SrcBox.Right = SrcBox.Right - (.Right - BattleSurfaceRect.Right)
  236.           End If
  237.           GraphicSurfaces(Pics(PicIndex).GraphicsLib).Restore
  238.           BattleSurface.BltFast .Left, .Top, GraphicSurfaces(Pics(PicIndex).GraphicsLib), SrcBox, DDBLTFAST_WAIT Or DDBLTFAST_SRCCOLORKEY
  239.         End If
  240.       End If
  241.     End If
  242.   End If
  243. End With
  244. End Sub
  245. Public Function ClipPic(X, Y, PicIndex, OffsetX, OffsetY) As Boolean
  246. ClipPic = False
  247. If X - OffsetX > BattleViewPort.Width Then
  248.   ClipPic = True
  249. End If
  250. If Y - OffsetY > BattleViewPort.Height Then
  251.   ClipPic = True
  252. End If
  253. If (X + Pics(PicIndex).Width) - OffsetX < 0 Then
  254.   ClipPic = True
  255. End If
  256. If (Y + Pics(PicIndex).Height) - OffsetY < 0 Then
  257.   ClipPic = True
  258. End If
  259. End Function
  260. Public Function Clip(X, Y) As Boolean
  261. If X < 0 Then
  262.   Clip = True
  263. End If
  264. If Y < 0 Then
  265.   Clip = True
  266. End If
  267. If X > BattleViewPort.Width Then
  268.   Clip = True
  269. End If
  270. If Y > BattleViewPort.Height Then
  271.   Clip = True
  272. End If
  273. End Function
  274. Public Function GetRGBVal(ColorValue, Pallete)
  275. Select Case Pallete
  276. Case PALLETE_RED
  277.   GetRGBVal = RGB(ColorValue, 0, 0)
  278. Case PALLETE_GREEN
  279.   GetRGBVal = RGB(0, ColorValue, 0)
  280. Case PALLETE_BLUE
  281.   GetRGBVal = RGB(0, 0, ColorValue)
  282. Case PALLETE_WHITE
  283.   GetRGBVal = RGB(ColorValue, ColorValue, ColorValue)
  284. Case PALLETE_YELLOW
  285.   GetRGBVal = RGB(ColorValue, ColorValue, 0)
  286. Case PALLETE_SKYBLUE
  287.   GetRGBVal = RGB(0, ColorValue / 2, ColorValue)
  288. End Select
  289. End Function
  290. Sub RenderTerrain()
  291. For X = Map.ProjectToMapX(View.Left) To Map.ProjectToMapX(View.Left + View.Width)
  292.   For Y = Map.ProjectToMapY(View.Top) To Map.ProjectToMapY(View.Top + View.Height)
  293.     Call RenderTerrainBlock(X, Y)
  294.   Next Y
  295. Next X
  296. End Sub
  297. Sub UpdateScenery()
  298. Static Count
  299. Count = Count + 1
  300. If Count = 6 Then
  301.   Count = 0
  302.   For X = Map.ProjectToMapX(View.Left) To Map.ProjectToMapX(View.Left + View.Width)
  303.     For Y = Map.ProjectToMapY(View.Top) To Map.ProjectToMapY(View.Top + View.Height)
  304.       If GroundBlocks(X, Y).TerrainType = TERRAINTYPE_WATER Then
  305.         Call RenderTerrainBlock(X, Y)
  306.         For I = 1 To GroundBlocks(X, Y).TerrainOverlayAmount
  307.           GroundBlocks(X, Y).AnimFrames(I) = GroundBlocks(X, Y).AnimFrames(I) + 1
  308.           If GroundBlocks(X, Y).AnimFrames(I) > Sprites(GroundBlocks(X, Y).SpriteNumbers(I)).SpriteGroups(GroundBlocks(X, Y).DamageAmount + 1).FrameMax Then
  309.             GroundBlocks(X, Y).AnimFrames(I) = 1
  310.           End If
  311.         Next I
  312.       End If
  313.     Next Y
  314.   Next X
  315. End If
  316. End Sub
  317. Sub MoveTerrain(Direction, Distance)
  318. Dim temprect As RECT
  319. Select Case Direction
  320. Case DIRECTION_UP
  321.   With temprect
  322.     .bottom = BattleViewPort.Height - Distance
  323.     .Right = BattleViewPort.Width
  324.   End With
  325.   TerrainSurface.BltFast 0, Distance, TerrainSurface, temprect, 0
  326.   For X = Map.ProjectToMapX(View.Left) To Map.ProjectToMapX(View.Left + View.Width)
  327.     For Y = Map.ProjectToMapY(View.Top) To Map.ProjectToMapY(View.Top) + GraphicsEngineData.TerrainRefreshSize
  328.       Call RenderTerrainBlock(X, Y)
  329.     Next Y
  330.   Next X
  331. Case DIRECTION_RIGHT
  332.   With temprect
  333.     .bottom = BattleViewPort.Height
  334.     .Right = BattleViewPort.Width
  335.     .Left = Distance
  336.   End With
  337.   TerrainSurface.BltFast 0, 0, TerrainSurface, temprect, 0
  338.   For Y = Map.ProjectToMapY(View.Top) To Map.ProjectToMapY(View.Top + View.Height)
  339.     For X = Map.ProjectToMapX(View.Left + View.Width) - GraphicsEngineData.TerrainRefreshSize To Map.ProjectToMapX(View.Left + View.Width) + 1
  340.       Call RenderTerrainBlock(X, Y)
  341.     Next X
  342.   Next Y
  343. Case DIRECTION_DOWN
  344.   With temprect
  345.     .Top = Distance
  346.     .bottom = BattleViewPort.Height
  347.     .Right = BattleViewPort.Width
  348.   End With
  349.   TerrainSurface.BltFast 0, 0, TerrainSurface, temprect, 0
  350.   For X = Map.ProjectToMapX(View.Left) To Map.ProjectToMapX(View.Left + View.Width)
  351.     For Y = Map.ProjectToMapY(View.Top + View.Height) - GraphicsEngineData.TerrainRefreshSize To Map.ProjectToMapY(View.Top + View.Height)
  352.       Call RenderTerrainBlock(X, Y)
  353.     Next Y
  354.   Next X
  355. Case DIRECTION_LEFT
  356.   With temprect
  357.     .bottom = BattleViewPort.Height
  358.     .Right = BattleViewPort.Width - Distance
  359.   End With
  360.   TerrainSurface.BltFast Distance, 0, TerrainSurface, temprect, 0
  361.   For Y = Map.ProjectToMapY(View.Top) To Map.ProjectToMapY(View.Top + View.Height)
  362.     For X = Map.ProjectToMapX(View.Left) To Map.ProjectToMapX(View.Left) + GraphicsEngineData.TerrainRefreshSize
  363.       Call RenderTerrainBlock(X, Y)
  364.     Next X
  365.   Next Y
  366. End Select
  367. End Sub
  368. Sub TilePic(PicIndex)
  369. Dim temprect As RECT
  370. With Pics(PicIndex)
  371.   TileMaxX = Int(ResolutionX / .Width)
  372.   TileMaxY = Int(ResolutionY / .Height)
  373.   temprect.bottom = .Height
  374.   temprect.Right = .Width
  375.   For X = 0 To TileMaxX - 1
  376.     For Y = 0 To TileMaxY - 1
  377.       
  378.       ddsBack.BltFast X * .Width, Y * .Height, GraphicSurfaces(Pics(PicIndex).GraphicsLib), temprect, DDBLTFAST_WAIT
  379.     
  380.     
  381.     
  382.     Next Y
  383.   Next X
  384. End With
  385. End Sub
  386. Sub DisplayControlPanel()
  387. Dim temprect As RECT
  388. With temprect
  389.   .Right = GameControlPanel.Width
  390.   .bottom = GameControlPanel.Height
  391. End With
  392. ddsBack.BltFast GameControlPanel.PortRect.Left, GameControlPanel.PortRect.Top, ControlPanelSurface, temprect, DDBLTFAST_WAIT
  393. End Sub
  394. Sub RenderMoneyValue()
  395. Call DisplayText("CREDITS: " & Format$(Player(LocalPlayer.PlayerIndex).Money, "0000"), 1, 1, PALLETE_WHITE)
  396. End Sub
  397. Sub RenderRadar()
  398. If RadarWindow.Enabled = True Then
  399.   ddsBack.BltFast RadarWindow.PortRect.Left, RadarWindow.PortRect.Top, GraphicSurfaces(Pics(InGameConstants(InGameConstant_PICINDEX_RadarBackground)).GraphicsLib), Pics(InGameConstants(InGameConstant_PICINDEX_RadarBackground)).SourceRect, DDBLTFAST_WAIT
  400. End If
  401. End Sub
  402. Sub RedrawControlPanel()
  403. For I = 1 To Int(ResolutionX / Pics(InGameConstants(InGameConstant_PICINDEX_ControlPanelBackground)).Width)
  404.   ControlPanelSurface.BltFast XPos, 0, GraphicSurfaces(Pics(InGameConstants(InGameConstant_PICINDEX_ControlPanelBackground)).GraphicsLib), Pics(InGameConstants(InGameConstant_PICINDEX_ControlPanelBackground)).SourceRect, DDBLTFAST_WAIT
  405.   XPos = XPos + Pics(InGameConstants(InGameConstant_PICINDEX_ControlPanelBackground)).Width
  406. Next I
  407. ControlPanelSurface.BltFast RadarButton.PortRect.Left, RadarButton.PortRect.Top - GameControlPanel.PortRect.Top, GraphicSurfaces(Pics(InGameConstants(InGameConstant_PICINDEX_RadarButtonPic)).GraphicsLib), Pics(InGameConstants(InGameConstant_PICINDEX_RadarButtonPic)).SourceRect, DDBLTFAST_WAIT
  408. Call RedrawBuildWindows
  409. End Sub
  410. Sub RedrawBuildWindows()
  411. If Player(LocalPlayer.PlayerIndex).BuildClassesActive > 0 Then
  412.   For I = 1 To MAXBUILDWINDOWS
  413.     If Player(LocalPlayer.PlayerIndex).BuildClasses(Player(LocalPlayer.PlayerIndex).CurrentlySelectedBuildClass + (I - 1)).Active = True Then
  414.       CurrentDisplayBuildClass = Player(LocalPlayer.PlayerIndex).BuildClasses(Player(LocalPlayer.PlayerIndex).CurrentlySelectedBuildClass + (I - 1)).ClassReference
  415.       ControlPanelSurface.BltFast BuildWindows(I).PortRect.Left - GameControlPanel.PortRect.Left, BuildWindows(I).PortRect.Top - GameControlPanel.PortRect.Top, GraphicSurfaces(Pics(ObjModels(CurrentDisplayBuildClass).Attributes(ATTRIBUTE_BUILDPICTURE)).GraphicsLib), Pics(ObjModels(CurrentDisplayBuildClass).Attributes(ATTRIBUTE_BUILDPICTURE)).SourceRect, DDBLTFAST_WAIT
  416.       For I2 = 1 To Player(LocalPlayer.PlayerIndex).BuildsInProgressesActive
  417.         If Player(LocalPlayer.PlayerIndex).BuildClasses(Player(LocalPlayer.PlayerIndex).CurrentlySelectedBuildClass + (I - 1)).ClassReference = Player(LocalPlayer.PlayerIndex).BuildsInProgress(I2).ClassReference Then
  418.           If Player(LocalPlayer.PlayerIndex).BuildsInProgress(I2).CanBePlaced = True Then
  419.             ControlPanelSurface.BltFast BuildWindows(I).PortRect.Left - GameControlPanel.PortRect.Left, BuildWindows(I).PortRect.Top - GameControlPanel.PortRect.Top, GraphicSurfaces(Pics(InGameConstants(InGameConstant_PICINDEX_BuildReadyPic)).GraphicsLib), Pics(InGameConstants(InGameConstant_PICINDEX_BuildReadyPic)).SourceRect, DDBLTFAST_WAIT Or DDBLTFAST_SRCCOLORKEY
  420.             Player(LocalPlayer.PlayerIndex).BuildClasses(Player(LocalPlayer.PlayerIndex).CurrentlySelectedBuildClass + (I - 1)).Enabled = True
  421.             Exit For
  422.           End If
  423.         
  424.         End If
  425.       Next I2
  426.       If Player(LocalPlayer.PlayerIndex).BuildClasses(Player(LocalPlayer.PlayerIndex).CurrentlySelectedBuildClass + (I - 1)).Enabled = False Then
  427.         ControlPanelSurface.BltFast BuildWindows(I).PortRect.Left - GameControlPanel.PortRect.Left, BuildWindows(I).PortRect.Top - GameControlPanel.PortRect.Top, GraphicSurfaces(Pics(InGameConstants(InGameConstant_PICINDEX_BuildDisabledPic)).GraphicsLib), Pics(InGameConstants(InGameConstant_PICINDEX_BuildDisabledPic)).SourceRect, DDBLTFAST_WAIT Or DDBLTFAST_SRCCOLORKEY
  428.       End If
  429.     End If
  430.   Next I
  431. End If
  432. End Sub
  433. Sub Render()
  434. 'Beta information
  435. If GraphicsEngineData.TotalRefresh = True Then
  436.   GraphicsEngineData.TotalRefresh = False
  437.   Call RedrawControlPanel
  438.   Call RenderTerrain
  439. End If
  440. Call DisplayControlPanel
  441. Call RenderBattleView
  442. Call RenderMoneyValue
  443. For I = 1 To Internet.MaxMessages
  444.   If Internet.InternetMessageBox.LinesActive(I) = True Then
  445.     Call DisplayText(Internet.InternetMessageBox.TextLines(I), 12, 17 + ((I - 1) * FONT_SPACINGY), PALLETE_WHITE)
  446.     MaxMessage = I
  447.   End If
  448. Next I
  449. If InterfaceFlags.WritingAMessage = True Then
  450.   Call DisplayText("say: " & InterfaceFlags.Message, 12, 17 + (MaxMessage * FONT_SPACINGY), 0)
  451. End If
  452. Call RenderRadar
  453. If MessageWindow.Active = True Then Call DisplayMessageWindow
  454. Call DrawCursor
  455. Call SwapScreen
  456. End Sub
  457. Private Sub RenderTerrainBlock(GroundX, GroundY)
  458. Dim BltType As Integer
  459. If GroundX < 0 Then Exit Sub
  460. If GroundY < 0 Then Exit Sub
  461. DisplayX = GameInterface.ProjectXToView(Map.UnProjectToMapX(GroundX))
  462. DisplayY = GameInterface.ProjectYToView(Map.UnProjectToMapY(GroundY)) '- GroundBlocks(GroundX, GroundY).Height
  463. Call PutGraphicOntoTerrain(DisplayX, DisplayY, Sprites(GroundBlocks(GroundX, GroundY).SpriteNumbers(1)).SpriteGroups(GroundBlocks(GroundX, GroundY).DamageAmount + 1).Frames(GroundBlocks(GroundX, GroundY).AnimFrames(1)).PicNum, 0, BltType_Fast)
  464. For I = 2 To GroundBlocks(GroundX, GroundY).TerrainOverlayAmount
  465.   Call PutGraphicOntoTerrain(DisplayX, DisplayY, Sprites(GroundBlocks(GroundX, GroundY).SpriteNumbers(I)).SpriteGroups(GroundBlocks(GroundX, GroundY).DamageAmount + 1).Frames(GroundBlocks(GroundX, GroundY).AnimFrames(I)).PicNum, 0, BltType_Mask)
  466. Next I
  467. End Sub
  468. Private Sub AnimTerrainBlock(GroundX, GroundY)
  469. For I = 1 To GroundBlocks(GroundX, GroundY).TerrainOverlayAmount
  470.   GroundBlocks(GroundX, GroundY).AnimFrames(I) = GroundBlocks(GroundX, GroundY).AnimFrames(I) + 1
  471.   If GroundBlocks(GroundX, GroundY).AnimFrames(I) > Sprites(GroundBlocks(GroundX, GroundY).SpriteNumbers(I)).SpriteGroups(GroundBlocks(GroundX, GroundY).DamageAmount + 1).FrameMax Then
  472.     GroundBlocks(GroundX, GroundY).AnimFrames(I) = 1
  473.   End If
  474. Next I
  475. End Sub
  476. Private Sub DrawStraightLine(X, Y, Distance, R, G, B, Direction)
  477. X1 = X
  478. Y1 = Y
  479. RGBVAL = RGB(R, G, B)
  480. SetPixelV lhdc, X1, Y1, RGBVAL
  481. For I = 1 To Distance
  482.   Select Case Direction
  483.   Case DIRECTION_UP
  484.     Y1 = Y1 - 1
  485.   Case DIRECTION_DOWN
  486.     Y1 = Y1 + 1
  487.   Case DIRECTION_LEFT
  488.     X1 = X1 - 1
  489.   Case DIRECTION_RIGHT
  490.     X1 = X1 + 1
  491.   End Select
  492.   SetPixelV lhdc, X1, Y1, RGBVAL
  493. Next I
  494. End Sub
  495. Private Sub RenderSelectedBoxes()
  496. BattleSurface.GetDC lhdc
  497. 'Selected object's outline
  498. For I = 1 To GameInterface.ObjectSelectedList.IndexesActive
  499.   With Objects(ObjectSelectedList.Indexes(I))
  500.     spritewidth = Pics(Sprites(.Sprite.SpriteNumber).SpriteGroups(.Sprite.SpriteGroupNumber).Frames(.Sprite.SpriteFrameNumber).PicNum).Width
  501.     spriteheight = Pics(Sprites(.Sprite.SpriteNumber).SpriteGroups(.Sprite.SpriteGroupNumber).Frames(.Sprite.SpriteFrameNumber).PicNum).Height
  502.     OffX = ObjModels(.ModelIndex).Attributes(ATTRIBUTE_SPRITEPOSITIONX)
  503.     OffY = ObjModels(.ModelIndex).Attributes(ATTRIBUTE_SPRITEPOSITIONY)
  504.     CenterX = ProjectXToView(.Position.X)
  505.     CenterY = ProjectYToView(.Position.Y)
  506.     Call DrawStraightLine(CenterX - OffX, CenterY - OffY, 4, 150, 150, 150, DIRECTION_RIGHT)
  507.     Call DrawStraightLine(CenterX - OffX, CenterY - OffY, 4, 150, 150, 150, DIRECTION_DOWN)
  508.     
  509.     Call DrawStraightLine((CenterX - OffX) + spritewidth, (CenterY - OffY) + spriteheight, 4, 150, 150, 150, DIRECTION_UP)
  510.     Call DrawStraightLine((CenterX - OffX) + spritewidth, (CenterY - OffY) + spriteheight, 4, 150, 150, 150, DIRECTION_LEFT)
  511.    
  512.     Call DrawStraightLine(CenterX - OffX, (CenterY - OffY) + spriteheight, 4, 150, 150, 150, DIRECTION_UP)
  513.     Call DrawStraightLine(CenterX - OffX, (CenterY - OffY) + spriteheight, 4, 150, 150, 150, DIRECTION_RIGHT)
  514.     
  515.     Call DrawStraightLine((CenterX - OffX) + spritewidth, CenterY - OffY, 4, 150, 150, 150, DIRECTION_DOWN)
  516.     Call DrawStraightLine((CenterX - OffX) + spritewidth, CenterY - OffY, 4, 150, 150, 150, DIRECTION_LEFT)
  517.    
  518.    
  519.     Call DrawBox((CenterX - OffX) + 5, CenterY - OffY - 1, ((CenterX - OffX) + spritewidth) - 5, CenterY - OffY + 1, 0, 100, 0, 0, 0, 0, LINEMODE_NORMAL)
  520.     HealthBright = .Properties(PROPERTY_HEALTH) / (ObjModels(.ModelIndex).Attributes(ATTRIBUTE_HEALTH) / 255)
  521.     Call DrawLine((CenterX - OffX) + 6, CenterY - OffY, ((CenterX - OffX) + spritewidth) - 6, CenterY - OffY, 0, 0, HealthBright, 0, 0, 0, LINEMODE_NORMAL)
  522.   End With
  523. Next I
  524. BattleSurface.ReleaseDC lhdc
  525. End Sub
  526. Sub RenderInterface()
  527.  
  528. If InterfaceFlags.PlacingABuilding = True Then
  529.     Dim TempPos As Point3D
  530.     'For rendering the build option
  531.     ModelNum = InterfaceFlags.PlaceIndex
  532.     TempPos = Map.RoundToMap3DPoint(Mouse.Position)
  533.     Call PutGraphicOntoBattleView(TempPos.X, TempPos.Y, SpriteStuff.Sprites(ObjModels(ModelNum).Attributes(ATTRIBUTE_SPRITE)).SpriteGroups(1).Frames(1).PicNum, 0, ObjModels(ModelNum).Attributes(ATTRIBUTE_SPRITEPOSITIONX), ObjModels(ModelNum).Attributes(ATTRIBUTE_SPRITEPOSITIONY))
  534. End If
  535.  
  536. BattleSurface.GetDC lhdc
  537. 'Mouse-Box for selecting objects
  538. If Mouse.IsDragging = True Then
  539.   If Math.GetDistance(Mouse.DragCurrentPosition, Mouse.DragStartPosition) > 8 Then
  540.     With Mouse.DragCurrentPosition
  541.       FromX = .X - BattleViewPort.PortRect.Left
  542.       FromY = .Y - BattleViewPort.PortRect.Top
  543.       ToX = Mouse.DragStartPosition.X - BattleViewPort.PortRect.Left
  544.       ToY = Mouse.DragStartPosition.Y - BattleViewPort.PortRect.Top
  545.     End With
  546.     With BattleViewPort
  547.       If ToX > .Width - 1 Then ToX = .Width - 1
  548.       If ToY > .Height - 1 Then ToY = .Height - 1
  549.     End With
  550.     If ToX - 4 < FromX Then
  551.       If ToX + 4 > FromX Then
  552.         If ToY - 4 < FromY Then
  553.           If ToY + 4 > FromY Then
  554.             DontDrawLine = True
  555.           End If
  556.         End If
  557.       End If
  558.     End If
  559.     If DontDrawLine = False Then Call DrawBox(FromX, FromY, ToX, ToY, 255, 0, 0, 0, 0, 255, LINEMODE_SHADE)
  560.   End If
  561. End If
  562. BattleSurface.ReleaseDC lhdc
  563. End Sub
  564. Sub RenderBattleView()
  565. If GameEngine.View.ScrollSpeedEW = 0 Then
  566.   If GameEngine.View.ScrollSpeedNS = 0 Then
  567.     
  568.     Call UpdateScenery
  569.   End If
  570. End If
  571. BattleSurface.BltFast 0, 0, TerrainSurface, BattleSurfaceRect, 0
  572. Call RenderObjects
  573. Call RenderVisualEffects
  574. Call RenderSelectedBoxes
  575. Call RenderInterface
  576. 'puts the completed scene onto the backbuffer
  577. ddsBack.BltFast BattleViewPort.PortRect.Left, BattleViewPort.PortRect.Top, BattleSurface, BattleSurfaceRect, DDBLTFAST_WAIT
  578. End Sub
  579. Sub RenderVisualEffects()
  580. BattleSurface.GetDC lhdc
  581.  
  582. Call RenderSparkles
  583. Call RenderSparks
  584.  
  585. BattleSurface.ReleaseDC lhdc
  586.  
  587. Call RenderAnimations
  588. End Sub
  589. Sub RenderObjects()
  590. Dim EliminatedObjects(MAXOBJECTS) As Boolean, EntitiesToRender(MAXOBJECTS), RenderX(MAXOBJECTS), RenderY(MAXOBJECTS), Clips(MAXOBJECTS) As Boolean
  591. BestRenderY = ResolutionY + 100
  592. ClosestRenderY = -9999
  593. For I = 1 To ObjectsActive
  594.   RenderX(I) = ProjectXToView(Objects(I).Position.X)
  595.   RenderY(I) = ProjectYToView(Objects(I).Position.Y) - (Objects(I).Position.Z / 3)
  596.   If ObjModels(Objects(I).ModelIndex).ObjClassName = "TestBase" Then
  597.      dsfsdf = 4
  598.   End If
  599. Next I
  600. For I = 1 To ObjectsActive
  601.   With Objects(I)
  602.     If .Frozen = False Then
  603.       If CheckObject(I, OBJCHECK_VISIBLE) = True Then
  604.         Clips(I) = ClipPic(RenderX(I), RenderY(I), SpriteStuff.Sprites(.Sprite.SpriteNumber).SpriteGroups(.Sprite.SpriteGroupNumber).Frames(.Sprite.SpriteFrameNumber).PicNum, ObjModels(.ModelIndex).Attributes(ATTRIBUTE_SPRITEPOSITIONX), ObjModels(.ModelIndex).Attributes(ATTRIBUTE_SPRITEPOSITIONY))
  605.       Else
  606.         Clips(I) = True
  607.       End If
  608.     Else
  609.       Clips(I) = True
  610.     End If
  611.   End With
  612. Next I
  613. For I2 = 1 To ObjectsActive
  614.     If Clips(I2) = False Then
  615.         ClosestRenderY = -9999
  616.         ClosestRenderObj = NOOBJECT
  617.         For I = 1 To ObjectsActive
  618.           If EliminatedObjects(I) = False Then
  619.             If CheckObject(I, OBJCHECK_ALIVE) = True Then
  620.               If Clips(I) = False Then
  621.                 If RenderY(I) <= BestRenderY Then
  622.                   If RenderY(I) >= ClosestRenderY Then
  623.                     ClosestRenderY = RenderY(I)
  624.                     ClosestRenderObj = I
  625.                   End If
  626.                 End If
  627.               End If
  628.             End If
  629.           End If
  630.         Next I
  631.         If ClosestRenderObj <> NOOBJECT Then
  632.           EliminatedObjects(ClosestRenderObj) = True
  633.           NextToRender = NextToRender + 1
  634.           EntitiesToRender(NextToRender) = ClosestRenderObj
  635.         End If
  636.     End If
  637. Next I2
  638. If NextToRender > 0 Then
  639.   For I = NextToRender To 1 Step -1
  640.     With Objects(EntitiesToRender(I))
  641.       If ObjModels(.ModelIndex).Abilities(ABILITY_HASSHADOW) = True Then
  642.         If .Position.Z > GroundBlocks(.MapPosition.X, .MapPosition.Y).Height Then
  643.           Call PutGraphicOntoBattleView(RenderX(EntitiesToRender(I)), ProjectYToView(Objects(EntitiesToRender(I)).Position.Y) - (GroundBlocks(.MapPosition.X, .MapPosition.Y).Height / 3), ObjModels(.ModelIndex).Attributes(ATTRIBUTE_SHADOWPIC), 0, ObjModels(.ModelIndex).Attributes(ATTRIBUTE_TOPSPRITEPOSITIONX), ObjModels(.ModelIndex).Attributes(ATTRIBUTE_TOPSPRITEPOSITIONY))
  644.         End If
  645.       End If
  646.       Call PutGraphicOntoBattleView(RenderX(EntitiesToRender(I)), RenderY(EntitiesToRender(I)), SpriteStuff.Sprites(.Sprite.SpriteNumber).SpriteGroups(.Sprite.SpriteGroupNumber).Frames(.Sprite.SpriteFrameNumber).PicNum, .DisplayDirection, ObjModels(.ModelIndex).Attributes(ATTRIBUTE_SPRITEPOSITIONX), ObjModels(.ModelIndex).Attributes(ATTRIBUTE_SPRITEPOSITIONY))
  647.       If ObjModels(.ModelIndex).Abilities(ABILITY_BODYISBISECTED) = True Then
  648.         Call PutGraphicOntoBattleView(RenderX(EntitiesToRender(I)), RenderY(EntitiesToRender(I)), SpriteStuff.Sprites(.TopSprite.SpriteNumber).SpriteGroups(.TopSprite.SpriteGroupNumber).Frames(.TopSprite.SpriteFrameNumber).PicNum, .TopDisplayDirection, ObjModels(.ModelIndex).Attributes(ATTRIBUTE_TOPSPRITEPOSITIONX), ObjModels(.ModelIndex).Attributes(ATTRIBUTE_TOPSPRITEPOSITIONY))
  649.       End If
  650.     End With
  651.   Next I
  652. End If
  653. End Sub
  654.  
  655. Sub RenderAnimations()
  656. 'Animations!
  657. For I = 1 To VisualEffects.AnimsActive
  658.   With Animations(I)
  659.     If .Active = True Then
  660.       RenderX = ProjectXToView(.Position.X)
  661.       RenderY = ProjectYToView(.Position.Y)
  662.       If Clip(RenderX, RenderY) = False Then
  663.         PicNum = SpriteStuff.Sprites(.SpriteNum).SpriteGroups(1).Frames(.CurrentFrame).PicNum
  664.         Call PutGraphicOntoBattleView(RenderX, RenderY, PicNum, .CurrentFrame, Pics(PicNum).HalfWidth, Pics(PicNum).HalfHeight)
  665.       End If
  666.     End If
  667.   End With
  668. Next I
  669. End Sub
  670. Sub RenderSparks()
  671. For I = 1 To SparksActive
  672.   With Sparks(I)
  673.     If .Active = True Then
  674.       RenderX = ProjectXToView(.Position.X)
  675.       RenderY = ProjectYToView(.Position.Y) - (.Position.Z / 2)
  676.       If Clip(RenderX, RenderY) = False Then
  677.         HealthVal = .Health + 50
  678.         If HealthVal > 255 Then HealthVal = 255
  679.         ColVal = GetRGBVal(HealthVal, .Pallete)
  680.         a = SetPixelV(lhdc, RenderX, RenderY, ColVal)
  681.       End If
  682.     End If
  683.   End With
  684. Next I
  685. End Sub
  686. Public Sub RenderSparkles()
  687. For I = 1 To SparklesActive
  688.   With Sparkles(I)
  689.     If .Active = True Then
  690.       For I2 = 1 To 3
  691.         RenderX = ProjectXToView(.Position.X) + ((2 * Rnd) - 1)
  692.         RenderY = (ProjectYToView(.Position.Y) - (.Position.Z / 2)) + ((2 * Rnd) - 1)
  693.         If Clip(RenderX, RenderY) = False Then
  694.           ColVal = GetRGBVal(.Health, .Pallete)
  695.           a = SetPixelV(lhdc, RenderX, RenderY, ColVal)
  696.         End If
  697.       Next I2
  698.     End If
  699.   End With
  700. Next I
  701. End Sub
  702. Sub DisplayMessageWindow()
  703. Dim temprect As RECT
  704. temprect.Top = 0
  705. temprect.Left = 0
  706. temprect.bottom = Pics(InGameConstants(InGameConstant_PICINDEX_MessageWindowPic)).Height
  707. temprect.Right = Pics(InGameConstants(InGameConstant_PICINDEX_MessageWindowPic)).Width
  708. ddsBack.BltFast ResolutionMidX - Pics(InGameConstants(InGameConstant_PICINDEX_MessageWindowPic)).HalfWidth, ResolutionMidY - Pics(InGameConstants(InGameConstant_PICINDEX_MessageWindowPic)).HalfHeight, GraphicSurfaces(Pics(InGameConstants(InGameConstant_PICINDEX_MessageWindowPic)).GraphicsLib), temprect, 0
  709. PlaceX = ResolutionMidX - (((Len(MessageWindow.Caption) + 1) * FONT_SPACINGX) / 2)
  710. PlaceY = (ResolutionMidY - Pics(InGameConstants(InGameConstant_PICINDEX_MessageWindowPic)).HalfHeight)
  711. Call DisplayText(MessageWindow.Caption, PlaceX, PlaceY + 13, 0)
  712.  
  713. LineSize = 26
  714. EndPoint = LineSize
  715. If EndPoint > Len(MessageWindow.Text) Then EndPoint = Len(MessageWindow.Text)
  716. StartPoint = 1
  717. Do
  718.   Call DisplayText(Mid$(MessageWindow.Text, StartPoint, (EndPoint - StartPoint) + 1), (ResolutionMidX - Pics(InGameConstants(InGameConstant_PICINDEX_MessageWindowPic)).HalfWidth) + 15, PlaceY + 38 + (LineCount * FONT_SPACINGY), 0)
  719.   If EndPoint = Len(MessageWindow.Text) Then Exit Do
  720.   StartPoint = StartPoint + LineSize
  721.   If StartPoint > Len(MessageWindow.Text) Then Exit Do
  722.   EndPoint = EndPoint + LineSize
  723.   If EndPoint > Len(MessageWindow.Text) Then EndPoint = Len(MessageWindow.Text)
  724.   LineCount = LineCount + 1
  725. Loop
  726. End Sub
  727. Sub OpenGraphicsDevice()
  728. ' Set some constant values (from WIN32API.TXT).
  729. Const conHwndTopmost = -1
  730. Const conHwndNoTopmost = -2
  731. Const conSwpNoActivate = &H10
  732. Const conSwpShowWindow = &H40
  733.  
  734. Call ViewForm.OpenGameView
  735. ' Turn on the TopMost attribute.
  736. SetWindowPos ViewForm.hwnd, conHwndTopmost, 0, 0, 0, 0, conSwpNoActivate Or conSwpShowWindow
  737.  
  738. DirectDrawCreate ByVal 0&, dd, Nothing
  739. ' This app is full screen and will change the display mode
  740. dd.SetCooperativeLevel ViewForm.hwnd, DDSCL_EXCLUSIVE Or DDSCL_FULLSCREEN
  741. ' Set the display mode
  742. dd.SetDisplayMode ResolutionX, ResolutionY, ColorDepth, 0, 0
  743. With ddsdFront
  744.   ' Structure size
  745.   .dwSize = Len(ddsdFront)
  746.   ' Use DDSD_CAPS and BackBufferCount
  747.   .dwFlags = DDSD_CAPS Or DDSD_BACKBUFFERCOUNT
  748.   ' Primary, flipable surface
  749.   
  750.   If Program.ProgramData.UsesSystemMemoryForBackbuffer = True Then
  751.     .DDSCAPS.dwCaps = DDSCAPS_PRIMARYSURFACE Or DDSCAPS_FLIP Or DDSCAPS_COMPLEX Or DDSCAPS_SYSTEMMEMORY
  752.   Else
  753.     .DDSCAPS.dwCaps = DDSCAPS_PRIMARYSURFACE Or DDSCAPS_FLIP Or DDSCAPS_COMPLEX
  754.   End If
  755.   ' One back buffer (you can try 2)
  756.   .dwBackBufferCount = 1
  757. End With
  758. WindowRect.Top = 0
  759. WindowRect.Left = 0
  760. WindowRect.Right = ResolutionX
  761. WindowRect.bottom = ResolutionY
  762. BattleSurfaceRect.Top = 0
  763. BattleSurfaceRect.Left = 0
  764. BattleSurfaceRect.Right = BattleViewPort.Width
  765. BattleSurfaceRect.bottom = BattleViewPort.Height
  766.  
  767. dd.CreateSurface ddsdFront, ddsFront, Nothing
  768. ddCaps.dwCaps = DDSCAPS_BACKBUFFER
  769. ddsFront.GetAttachedSurface ddCaps, ddsBack
  770. fx.ddckSrcColorkey.dwColorSpaceHighValue = RGB(0, 0, 0)
  771. fx.ddckSrcColorkey.dwColorSpaceLowValue = RGB(0, 0, 0)
  772. fx.dwSize = Len(fx)
  773. FxClear.dwSize = Len(fx)
  774. FxClear.dwFillColor = RGB(0, 0, 0)
  775. GraphicsEngineData.DeviceOpen = True
  776. Set TerrainSurface = CreateSurface(BattleViewPort.Width, BattleViewPort.Height)
  777. Set BattleSurface = CreateSurface(BattleViewPort.Width, BattleViewPort.Height)
  778. Set ControlPanelSurface = CreateSurface(GameControlPanel.Width, GameControlPanel.Height)
  779. 'ShowCursor 0
  780. End Sub
  781. Public Sub ChangeGraphicsMode(ResX, ResY, BitDepth)
  782. ResolutionX = ResX
  783. ResolutionY = ResY
  784. ResolutionMidX = ResX / 2
  785. ResolutionMidY = ResY / 2
  786. FONT_LastCharacter = ResolutionX / FONT_SPACINGX
  787. FONT_LastLine = ResolutionY / FONT_SPACINGY
  788. ColorDepth = BitDepth
  789. End Sub
  790. Sub ClearBackBuffer()
  791. Call GraphicsEngine.TilePic(InGameConstants(InGameConstant_PICINDEX_ClearBackground))
  792. End Sub
  793. Sub TempOpenGraphicsDevice()
  794. Call ViewForm.OpenGameView
  795. DirectDrawCreate ByVal 0&, dd, Nothing
  796. ' This app is full screen and will change the display mode
  797. dd.SetCooperativeLevel ViewForm.hwnd, DDSCL_EXCLUSIVE Or DDSCL_FULLSCREEN
  798. ' Set the display mode
  799. dd.SetDisplayMode ResolutionX, ResolutionY, ColorDepth, 0, 0
  800. With ddsdFront
  801.   ' Structure size
  802.   .dwSize = Len(ddsdFront)
  803.   ' Use DDSD_CAPS and BackBufferCount
  804.   .dwFlags = DDSD_CAPS Or DDSD_BACKBUFFERCOUNT
  805.   ' Primary, flipable surface
  806.   
  807.   If Program.ProgramData.UsesSystemMemoryForBackbuffer = True Then
  808.     .DDSCAPS.dwCaps = DDSCAPS_PRIMARYSURFACE Or DDSCAPS_FLIP Or DDSCAPS_COMPLEX Or DDSCAPS_SYSTEMMEMORY
  809.   Else
  810.     .DDSCAPS.dwCaps = DDSCAPS_PRIMARYSURFACE Or DDSCAPS_FLIP Or DDSCAPS_COMPLEX
  811.   End If
  812.   ' One back buffer (you can try 2)
  813.   .dwBackBufferCount = 1
  814. End With
  815. dd.CreateSurface ddsdFront, ddsFront, Nothing
  816. ddCaps.dwCaps = DDSCAPS_BACKBUFFER
  817. ddsFront.GetAttachedSurface ddCaps, ddsBack
  818. fx.ddckSrcColorkey.dwColorSpaceHighValue = 0
  819. fx.ddckSrcColorkey.dwColorSpaceLowValue = 0
  820. fx.dwSize = Len(fx)
  821. FxClear.dwSize = Len(fx)
  822. FxClear.dwFillColor = RGB(0, 0, 0)
  823. GraphicsEngineData.DeviceOpen = True
  824. TerrainSurface.Restore
  825. BattleSurface.Restore
  826. ControlPanelSurface.Restore
  827. 'ShowCursor 0
  828. End Sub
  829. Sub TempCloseGraphicsDevice()
  830. DoEvents
  831. dd.FlipToGDISurface
  832. dd.RestoreDisplayMode
  833. dd.SetCooperativeLevel 0, DDSCL_NORMAL
  834. GraphicsEngineData.DeviceOpen = False
  835. End Sub
  836. Sub CloseGraphicsDevice()
  837. 'ShowCursor 1
  838. Call SpriteStuff.UnloadGraphicLibraries
  839. Set TerrainSurface = Nothing
  840. Set ControlPanelSurface = Nothing
  841. Set BattleSurface = Nothing
  842. DoEvents
  843. dd.FlipToGDISurface
  844. dd.RestoreDisplayMode
  845. dd.SetCooperativeLevel 0, DDSCL_NORMAL
  846. Set ddsBack = Nothing
  847. Set ddsFront = Nothing
  848. Set dd = Nothing
  849. Call ViewForm.DestroyGameView
  850. GraphicsEngineData.DeviceOpen = False
  851. End Sub
  852. Sub DrawBox(X1, Y1, X2, Y2, R1, G1, B1, R2, G2, B2, Mode)
  853. If Mode = LINEMODE_NORMAL Then
  854.   If X2 < X1 Then
  855.     X3 = X1
  856.     X1 = X2
  857.     X2 = X1
  858.   End If
  859.   If Y2 < Y1 Then
  860.     Y3 = Y1
  861.     Y1 = Y2
  862.     Y2 = Y1
  863.   End If
  864.   Color1 = RGB(R1, G1, B1)
  865.   Y = Y1
  866.   For X = X1 To X2
  867.     SetPixelV lhdc, X, Y, Color1
  868.   Next X
  869.   Y = Y2
  870.   For X = X1 To X2
  871.     SetPixelV lhdc, X, Y, Color1
  872.   Next X
  873.   X = X1
  874.   For Y = Y1 To Y2
  875.     SetPixelV lhdc, X, Y, Color1
  876.   Next Y
  877.   X = X2
  878.   For Y = Y1 To Y2
  879.     SetPixelV lhdc, X, Y, Color1
  880.   Next Y
  881. Else
  882.   Call DrawLine(X1, Y1, X2, Y1, R1, G1, B1, R2, G2, B2, Mode)
  883.   Call DrawLine(X1, Y1, X1, Y2, R1, G1, B1, R2, G2, B2, Mode)
  884.   Call DrawLine(X2, Y2, X2, Y1, R1, G1, B1, R2, G2, B2, Mode)
  885.   Call DrawLine(X2, Y2, X1, Y2, R1, G1, B1, R2, G2, B2, Mode)
  886. End If
  887. End Sub
  888. Sub DrawLine(X1, Y1, X2, Y2, R1, G1, B1, R2, G2, B2, Mode)
  889. On Error Resume Next
  890. XDiff = X1 - X2
  891. YDiff = Y1 - Y2
  892. If YDiff < 0 Then ChangeY = True: YDiff = -YDiff
  893. If XDiff < 0 Then ChangeX = True: XDiff = -XDiff
  894. If YDiff > XDiff Then
  895.   LengthOfLine = YDiff
  896.   XInc = XDiff / YDiff
  897.   YInc = 1
  898. Else
  899.   LengthOfLine = XDiff
  900.   YInc = YDiff / XDiff
  901.   XInc = 1
  902. End If
  903. If ChangeY = True Then YInc = -YInc
  904. If ChangeX = True Then XInc = -XInc
  905. CurrX = X1
  906. CurrY = Y1
  907. Select Case Mode
  908. Case LINEMODE_SHADE
  909.   RDiff = R2 - R1
  910.   RI = (RDiff / LengthOfLine)
  911.   GDiff = G2 - G1
  912.   GI = (GDiff / LengthOfLine)
  913.   BDiff = B2 - B1
  914.   BI = (BDiff / LengthOfLine)
  915. End Select
  916. SetPixelV lhdc, X1, Y1, RGB(R1, G1, B1)
  917. For I = 1 To LengthOfLine
  918.   CurrX = CurrX - XInc
  919.   CurrY = CurrY - YInc
  920.   Select Case Mode
  921.   Case LINEMODE_NORMAL
  922.     Color1 = RGB(R1, G1, B1)
  923.   Case LINEMODE_SHADE
  924.     Color1 = RGB(R1 + (RI * I), G1 + (GI * I), B1 + (BI * I))
  925.   End Select
  926.   SetPixelV lhdc, CurrX, CurrY, Color1
  927. Next I
  928. End Sub
  929. Private Function CreateSurface(Width, Height) As DirectDrawSurface2
  930. Dim ddsd As DDSURFACEDESC       ' Surface description
  931. Dim dds As DirectDrawSurface2   ' Created surface
  932. With ddsd
  933.     .dwSize = Len(ddsd)
  934.     .dwFlags = DDSD_CAPS Or DDSD_HEIGHT Or DDSD_WIDTH
  935.     .DDSCAPS.dwCaps = DDSCAPS_OFFSCREENPLAIN
  936.     .dwWidth = Width
  937.     .dwHeight = Height
  938. End With
  939. dd.CreateSurface ddsd, dds, Nothing
  940.  
  941. ' Restore the surface
  942. dds.Restore
  943. ' Returns the new surface
  944. Set CreateSurface = dds
  945. End Function
  946. Private Sub LoadGraphicOntoGraphicLib(Index, dd As DirectDraw2, ByVal strFile As String)
  947. Dim hbm As Long                 ' Handle on bitmap
  948. Dim bm As BITMAP                ' Bitmap header
  949. Dim ddsd As DDSURFACEDESC       ' Surface description
  950. Dim dds As DirectDrawSurface2   ' Created surface
  951. Dim hdcImage As Long            ' Handle on image
  952. Dim lhdc As Long                ' Handle on surface context
  953. ' Load bitmap
  954. hbm = LoadImage(ByVal 0&, strFile, IMAGE_BITMAP, 0, 0, LR_LOADFROMFILE Or LR_CREATEDIBSECTION)
  955. ' Get bitmap info
  956. GetObject hbm, Len(bm), bm
  957. ' Fill surface description
  958. With ddsd
  959.     .dwSize = Len(ddsd)
  960.     .dwFlags = DDSD_CAPS Or DDSD_HEIGHT Or DDSD_WIDTH
  961.     .DDSCAPS.dwCaps = DDSCAPS_OFFSCREENPLAIN Or DDSCAPS_SYSTEMMEMORY
  962.     .dwWidth = bm.bmWidth
  963.     .dwHeight = bm.bmHeight
  964. End With
  965. GraphicsLibs(Index).Width = bm.bmWidth
  966. GraphicsLibs(Index).HalfWidth = Int(bm.bmWidth / 2)
  967. GraphicsLibs(Index).Height = bm.bmHeight
  968. GraphicsLibs(Index).HalfHeight = Int(bm.bmHeight / 2)
  969. ' Create surface
  970. dd.CreateSurface ddsd, dds, Nothing
  971. ' Create memory device
  972. hdcImage = CreateCompatibleDC(ByVal 0&)
  973. ' Select the bitmap in this memory device
  974. SelectObject hdcImage, hbm
  975. ' Restore the surface
  976. dds.Restore
  977. ' Get the surface's DC
  978. dds.GetDC lhdc
  979. ' Copy from the memory device to the DirectDrawSurface
  980. StretchBlt lhdc, 0, 0, ddsd.dwWidth, ddsd.dwHeight, hdcImage, 0, 0, bm.bmWidth, bm.bmHeight, SRCCOPY
  981. ' Release the surface's DC
  982. dds.ReleaseDC lhdc
  983. ' Release the memory device and the bitmap
  984. DeleteDC hdcImage
  985. DeleteObject hbm
  986. ' Returns the new surface
  987. Set GraphicSurfaces(Index) = dds
  988. End Sub
  989. Private Function CreateDDSFromBitmapDirectly(dd As DirectDraw2, ByVal strFile As String) As DirectDrawSurface2
  990. Dim hbm As Long                 ' Handle on bitmap
  991. Dim bm As BITMAP                ' Bitmap header
  992. Dim ddsd As DDSURFACEDESC       ' Surface description
  993. Dim dds As DirectDrawSurface2   ' Created surface
  994. Dim hdcImage As Long            ' Handle on image
  995. Dim lhdc As Long                ' Handle on surface context
  996. ' Load bitmap
  997. hbm = LoadImage(ByVal 0&, strFile, IMAGE_BITMAP, 0, 0, LR_LOADFROMFILE Or LR_CREATEDIBSECTION)
  998. ' Get bitmap info
  999. GetObject hbm, Len(bm), bm
  1000. ' Fill surface description
  1001. With ddsd
  1002.     .dwSize = Len(ddsd)
  1003.     .dwFlags = DDSD_CAPS Or DDSD_HEIGHT Or DDSD_WIDTH
  1004.     .DDSCAPS.dwCaps = DDSCAPS_OFFSCREENPLAIN Or DDSCAPS_SYSTEMMEMORY
  1005.     .dwWidth = bm.bmWidth
  1006.     .dwHeight = bm.bmHeight
  1007. End With
  1008. ' Create surface
  1009. dd.CreateSurface ddsd, dds, Nothing
  1010. ' Create memory device
  1011. hdcImage = CreateCompatibleDC(ByVal 0&)
  1012. ' Select the bitmap in this memory device
  1013. SelectObject hdcImage, hbm
  1014. ' Restore the surface
  1015. dds.Restore
  1016. ' Get the surface's DC
  1017. dds.GetDC lhdc
  1018. ' Copy from the memory device to the DirectDrawSurface
  1019. StretchBlt lhdc, 0, 0, ddsd.dwWidth, ddsd.dwHeight, hdcImage, 0, 0, bm.bmWidth, bm.bmHeight, SRCCOPY
  1020. ' Release the surface's DC
  1021. dds.ReleaseDC lhdc
  1022. ' Release the memory device and the bitmap
  1023. DeleteDC hdcImage
  1024. DeleteObject hbm
  1025. ' Returns the new surface
  1026. Set CreateDDSFromBitmapDirectly = dds
  1027. End Function
  1028. Sub LoadGraphic(Index, Filename)
  1029. SpriteStuff.GraphicsLibs(Index).Active = True
  1030. Call GraphicsEngine.LoadGraphicOntoGraphicLib(Index, dd, Filename)
  1031. Call prepSrcColorKey(GraphicSurfaces(Index))
  1032. End Sub
  1033. Sub DisplayTextCenter(Text, Y, Pallete)
  1034. textlength = Len(Text)
  1035. X = ResolutionMidX - ((textlength * FONT_SPACINGX) / 2)
  1036. Call DisplayText(Text, X, Y, Pallete)
  1037. End Sub
  1038. Sub DisplayTextCenterRelative(Text, X, Y, Pallete)
  1039. textlength = Len(Text)
  1040. XDisp = X - ((textlength * FONT_SPACINGX) / 2)
  1041. YDisp = Y - ((FONT_SPACINGY) / 2)
  1042. Call DisplayText(Text, XDisp, YDisp, Pallete)
  1043. End Sub
  1044. Sub DisplayText(Text, X, Y, Pallete)
  1045. Dim DestBox As RECT, SrcBox As RECT
  1046. On Error Resume Next
  1047. TextString$ = UCase$(Text)
  1048. textlength = Len(TextString$)
  1049. For I = 1 To textlength
  1050.   CurrentCharacter$ = Mid$(TextString$, I, 1)
  1051.   If CurrentCharacter$ <> " " Then
  1052.       Select Case CurrentCharacter$
  1053.       Case "A"
  1054.         TextX = 0
  1055.         texty = 0
  1056.       Case "B"
  1057.         TextX = 1
  1058.         texty = 0
  1059.       
  1060.       Case "C"
  1061.         TextX = 2
  1062.         texty = 0
  1063.       Case "D"
  1064.         TextX = 3
  1065.         texty = 0
  1066.       Case "E"
  1067.         TextX = 4
  1068.         texty = 0
  1069.       Case "F"
  1070.         TextX = 5
  1071.         texty = 0
  1072.       
  1073.       Case "G"
  1074.         TextX = 6
  1075.         texty = 0
  1076.       Case "H"
  1077.         TextX = 7
  1078.         texty = 0
  1079.       Case "I"
  1080.         TextX = 8
  1081.         texty = 0
  1082.       Case "J"
  1083.         TextX = 9
  1084.         texty = 0
  1085.       Case "K"
  1086.         TextX = 10
  1087.         texty = 0
  1088.       Case "L"
  1089.         TextX = 11
  1090.         texty = 0
  1091.       Case "M"
  1092.         TextX = 12
  1093.         texty = 0
  1094.       Case "N"
  1095.         TextX = 13
  1096.         texty = 0
  1097.       Case "O"
  1098.         TextX = 14
  1099.         texty = 0
  1100.       Case "P"
  1101.         TextX = 15
  1102.         texty = 0
  1103.       Case "Q"
  1104.         TextX = 16
  1105.         texty = 0
  1106.       Case "R"
  1107.         TextX = 17
  1108.         texty = 0
  1109.       Case "S"
  1110.         TextX = 18
  1111.         texty = 0
  1112.       Case "T"
  1113.         TextX = 19
  1114.         texty = 0
  1115.       Case "U"
  1116.         TextX = 20
  1117.         texty = 0
  1118.       Case "V"
  1119.         TextX = 21
  1120.         texty = 0
  1121.       Case "W"
  1122.         TextX = 22
  1123.         texty = 0
  1124.       Case "X"
  1125.         TextX = 23
  1126.         texty = 0
  1127.       Case "Y"
  1128.         TextX = 24
  1129.         texty = 0
  1130.       Case "Z"
  1131.         TextX = 25
  1132.         texty = 0
  1133.       Case "1"
  1134.         TextX = 26
  1135.         texty = 0
  1136.       Case "2"
  1137.         TextX = 27
  1138.         texty = 0
  1139.       Case "3"
  1140.         TextX = 28
  1141.         texty = 0
  1142.       Case "4"
  1143.         TextX = 0
  1144.         texty = 1
  1145.       Case "5"
  1146.         TextX = 1
  1147.         texty = 1
  1148.       Case "6"
  1149.         TextX = 2
  1150.         texty = 1
  1151.       Case "7"
  1152.         TextX = 3
  1153.         texty = 1
  1154.       
  1155.       Case "8"
  1156.         TextX = 4
  1157.         texty = 1
  1158.       Case "9"
  1159.         TextX = 5
  1160.         texty = 1
  1161.       Case "0"
  1162.         TextX = 6
  1163.         texty = 1
  1164.       Case "."
  1165.         TextX = 7
  1166.         texty = 1
  1167.       Case ","
  1168.         TextX = 8
  1169.         texty = 1
  1170.       Case "?"
  1171.         TextX = 9
  1172.         texty = 1
  1173.       Case "!"
  1174.         TextX = 10
  1175.         texty = 1
  1176.       Case "*"
  1177.         TextX = 11
  1178.         texty = 1
  1179.       Case "/"
  1180.         TextX = 12
  1181.         texty = 1
  1182.       Case "\"
  1183.         TextX = 13
  1184.         texty = 1
  1185.       Case "["
  1186.         TextX = 14
  1187.         texty = 1
  1188.       Case "]"
  1189.         TextX = 15
  1190.         texty = 1
  1191.       Case "("
  1192.         TextX = 16
  1193.         texty = 1
  1194.       Case ")"
  1195.         TextX = 17
  1196.         texty = 1
  1197.       Case "$"
  1198.         TextX = 18
  1199.         texty = 1
  1200.       Case "#"
  1201.         TextX = 19
  1202.         texty = 1
  1203.       Case "<"
  1204.         TextX = 20
  1205.         texty = 1
  1206.       Case ">"
  1207.         TextX = 21
  1208.         texty = 1
  1209.       Case "&"
  1210.         TextX = 22
  1211.         texty = 1
  1212.       Case "@"
  1213.         TextX = 22
  1214.         texty = 1
  1215.       
  1216.       Case "-"
  1217.         TextX = 23
  1218.         texty = 1
  1219.       Case "+"
  1220.         TextX = 24
  1221.         texty = 1
  1222.       Case "="
  1223.         TextX = 25
  1224.         texty = 1
  1225.       Case "'"
  1226.         TextX = 26
  1227.         texty = 1
  1228.       Case CHARACTER_QOUTE
  1229.         TextX = 27
  1230.         texty = 1
  1231.       Case ":"
  1232.         TextX = 28
  1233.         texty = 1
  1234.       End Select
  1235.       If X < 0 Then
  1236.         DestBox.Left = ((FONT_LastCharacter - (-(I - 1) + textlength)) * FONT_SPACINGX) - FONT_SPACINGX
  1237.         DestBox.Right = DestBox.Left + FONT_SIZE
  1238.       Else
  1239.         DestBox.Left = ((I - 1) * FONT_SPACINGX) + X
  1240.         DestBox.Right = DestBox.Left + FONT_SIZE
  1241.       End If
  1242.       DestBox.Top = Y
  1243.       DestBox.bottom = DestBox.Top + FONT_SIZE
  1244.       SrcBox.Top = texty * FONT_SIZE
  1245.       SrcBox.bottom = (texty + 1) * FONT_SIZE
  1246.       SrcBox.Left = TextX * FONT_SIZE
  1247.       SrcBox.Right = (TextX + 1) * FONT_SIZE
  1248.       
  1249.       If Pallete = PALLETE_WHITE Then
  1250.         SrcBox.Top = SrcBox.Top + GraphicsLibs(InGameConstants(InGameConstant_PICINDEX_FontLib)).HalfHeight
  1251.         SrcBox.bottom = SrcBox.bottom + GraphicsLibs(InGameConstants(InGameConstant_PICINDEX_FontLib)).HalfHeight
  1252.       End If
  1253.       
  1254.       ' Set the transparent color
  1255.       GraphicSurfaces(InGameConstants(InGameConstant_PICINDEX_FontLib)).Restore
  1256.       ' Blit the image to the back buffer
  1257.  
  1258.       
  1259.       
  1260.       ddsBack.BltFast DestBox.Left, DestBox.Top, GraphicSurfaces(InGameConstants(InGameConstant_PICINDEX_FontLib)), SrcBox, DDBLTFAST_WAIT Or DDBLTFAST_SRCCOLORKEY
  1261.   
  1262.   
  1263.   
  1264.   End If
  1265. Next I
  1266. End Sub
  1267.